package com.yljk.servicemanager.oldbase;

import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.alibaba.android.arouter.launcher.ARouter;
import com.yilijk.base.utils.ActivityManagerUtils;
import com.yljk.servicemanager.constants.RouterApi;
import com.yljk.servicemanager.interfaceapi.BaiduApi;

import crossoverone.statuslib.StatusUtil;


public
 abstract  class ModuleBaseActivity extends AppCompatActivity implements IActivity {

    private BaiduApi baiduApi;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        if (savedInstanceState != null && true) {
            //重建时清除 fragment的状态
            savedInstanceState.remove("android:support:fragments");
        }
        super.onCreate(savedInstanceState);
        ActivityManagerUtils.addActivities(this);
        setContentView(bondLayout());
        //沉浸式布局
        if (Build.VERSION.SDK_INT >= 21) {
          StatusUtil.setUseStatusBarColor(this,Color.BLACK);
          StatusUtil.setSystemStatus(this,false,false);
        }
        //设置activity 禁止横屏
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        ARouter.getInstance().inject(this);
        baiduApi = (BaiduApi) ARouter.getInstance().build(RouterApi.BaiduImpl).navigation();
        initView();
        initData();
        initEvent();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        if (outState != null && true) {
            //销毁时不保存fragment的状态
            outState.remove("android:support:fragments");
        }
    }

    @Override
    public Resources getResources() {
        Resources resources = super.getResources();
        Configuration configuration = new Configuration();
        configuration.setToDefaults();
        resources.updateConfiguration(configuration, resources.getDisplayMetrics());
        return resources;
    }


    @Override
    protected void onStart() {
        baiduApi.onPageStart(this,this.getClass().toString());
        super.onStart();
    }

    @Override
    protected void onDestroy() {
        ActivityManagerUtils.removeActivities(this);
        baiduApi.onPageEnd(this,this.getClass().toString());
        super.onDestroy();
    }

    @Override
    protected void onResume() {
        baiduApi.onResume(this);
        super.onResume();
    }

    @Override
    protected void onPause() {
        baiduApi.onPause(this);
        super.onPause();
    }
}
interface IActivity {
    int bondLayout();
    void initView();
    void initData();
    void initEvent();
}

